local xiansi_viewas = fk.CreateSkill{
    name = "SP_heg__xiansi_viewas&",
}

Fk:loadTranslationTable{
    ["SP_heg__xiansi_viewas&"] = "陷嗣",
    [":SP_heg__xiansi_viewas&"] = "当你需使用【杀】时，你可以弃置刘封的两张相同颜色的“逆”，视为对其使用一张【杀】。",

    ["#SP_heg__xiansi_viewas&"] = "陷嗣：你可以移去刘封的两张相同颜色的“逆”，视为对其使用一张【杀】",
}

xiansi_viewas:addEffect("viewas", {
  anim_type = "negative",
  prompt = "#SP_heg__xiansi_viewas&",
  pattern = "slash",
  card_filter = Util.FalseFunc,
  view_as = function(self, cards)
    local c = Fk:cloneCard("slash")
    c.skillName = "SP_heg__xiansi_viewas&"
    return c
  end,
  before_use = function(self, player, use)
    local room = player.room
    for _, p in ipairs(use.tos) do
      if p:hasSkill("SP_heg__xiansi", true) and #p:getPile("heg__liufeng_ni") > 1 then
        local cards = p:getPile("heg__liufeng_ni")
        local chosen_cards = nil
        for i = 1, #cards - 1 do
          for j = i + 1, #cards do
            if Fk:getCardById(cards[i]).color == Fk:getCardById(cards[j]).color then
              chosen_cards = {cards[i], cards[j]}
              break
            end
          end
          if chosen_cards then break end
        end
        if chosen_cards then
          room:moveCards({
            from = p,
            ids = chosen_cards,
            toArea = Card.DiscardPile,
            moveReason = fk.ReasonPutIntoDiscardPile,
            skillName = "SP_heg__xiansi",
          })
          break
        end
      end
    end
  end,
  enabled_at_play = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function(p)
      if p:hasSkill("SP_heg__xiansi", true) and #p:getPile("heg__liufeng_ni") > 1 and p:hasShownSkill("SP_heg__xiansi") then
        local cards = p:getPile("heg__liufeng_ni")
        local chosen_cards = nil
        for i = 1, #cards - 1 do
          for j = i + 1, #cards do
            if Fk:getCardById(cards[i]).color == Fk:getCardById(cards[j]).color then
              chosen_cards = {cards[i], cards[j]}
              break
            end
          end
          if chosen_cards then break end
        end
        return chosen_cards ~= nil
      end
      return false
    end)
  end,
  enabled_at_response = function(self, player, response)
    return not response and table.find(Fk:currentRoom().alive_players, function(p)
      if p:hasSkill("SP_heg__xiansi", true) and #p:getPile("heg__liufeng_ni") > 1 and p:hasShownSkill("SP_heg__xiansi") then
        local cards = p:getPile("heg__liufeng_ni")
        local chosen_cards = nil
        for i = 1, #cards - 1 do
          for j = i + 1, #cards do
            if Fk:getCardById(cards[i]).color == Fk:getCardById(cards[j]).color then
              chosen_cards = {cards[i], cards[j]}
              break
            end
          end
          if chosen_cards then break end
        end
        return chosen_cards ~= nil
      end
      return false
    end)
  end,
  })

xiansi_viewas:addEffect("prohibit", {
    is_prohibited = function(self, from, to, card)
        if from and from:hasSkill("SP_heg__xiansi_viewas&", true) then
          return card.trueName == "slash" and table.contains(card.skillNames, "SP_heg__xiansi_viewas&") and
            not (to:hasSkill("SP_heg__xiansi", true) and #to:getPile("heg__liufeng_ni") > 1)
        end
      end,
  })

return xiansi_viewas